package com.st.chapter02;

import java.math.BigDecimal;
import java.util.Scanner;

import javax.security.auth.kerberos.KerberosKey;

import org.junit.Test;

public class Test2 {
	public static void main(String[] args) {

//		//行数
//		for (int i = 1; i <= 6; i++) {
//			//开始输空格
//			for(int j = 1;j <=7-i;j++) {
//				if(j <7-i) {
//					System.out.print(" ");	
//				}
//				//开始输*
//				if(j == (7-i)) {
//					for(int k = 1;k<=2*i-1;k++) {
//						if (k<(2*i-1)) {
//							System.out.print("*");
//						}
//						//判断是否换行
//						else if(k==(2*i-1)){
//							System.out.println("*");
//						}
//					}
//					
//				}
//			}
//		}

	}

	@Test
	public void test22() {
		for (int i = 1; i <= 6; i++) {
			for (int j = 1; j <= (6 - i); j++) {
				System.out.print("-");
			}
			for (int j = 1; j <= (2 * i - 1); j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}

	@Test
	public void Test8() {
		for (int i = 6; i >= 1; i--) {
			// 开始输空格
			for (int j = 1; j <= 7 - i; j++) {
				if (j < 7 - i) {
					System.out.print(" ");
				}
				// 开始输*
				if (j == (7 - i)) {
					for (int k = 1; k <= 2 * i - 1; k++) {
						if (k < (2 * i - 1)) {
							System.out.print("*");
						}
						// 判断是否换行
						else if (k == (2 * i - 1)) {
							System.out.println("*");
						}
					}

				}
			}
		}
	}

	@Test
	public void test3() {
		int sum1 = 0;
		int sum2 = 0;
		for (int i = 1; i <= 100; i++) {
			sum1 = sum1 + i;
			if (i % 2 == 0) {
				sum2 = sum2 + i;
			}
		}
		int sum3 = sum1 - sum2;
		System.out.println("偶数和：" + sum2 + "\t奇数和" + sum3);
	}

	@Test
	public void test4() {
		int count = 0;
		for (int i = 1; i <= 1000; i++) {
			if (i % 5 == 0) {
				System.out.print(i + "\t");
				count++;
				if (count % 3 == 0) {
					System.out.println();
				}
			}

		}
	}

	@Test
	public void test5() {
		int mul = 1;
		for (int i = 1; i <= 9; i++) {
			mul = mul * i;
		}
		System.out.println(mul);
	}

	@Test
	public void test6() {

		Scanner sc = new Scanner(System.in);
		double money = sc.nextDouble();

		if (money > 0 && money <= 10) {
			double jiangjin = mul(money, 0.1);
			System.out.println(jiangjin + "万元");
		} else if (money > 10 && money <= 20) {
			double jiangjin = add(1, mul(0.075, sub(money, 10))); // 1 + (money - 10)*0.075;
			System.out.println(jiangjin + "万元");
		} else if (money > 20 && money <= 40) {
			double jiangjin = add(1.75, mul(0.05, sub(money, 20)));// 1+ 0.75 +(money - 20)*0.05;
			System.out.println(jiangjin + "万元");
		} else if (money > 40 && money <= 60) {
			double jiangjin = add(2.75, mul(0.03, sub(money, 40)));// 1+ 0.75 + 1 + (money - 40)*0.03;
			System.out.println(jiangjin + "万元");
		} else if (money > 60 && money <= 100) {
			double jiangjin = add(3.35, mul(0.015, sub(money, 60)));// 1+ 0.75 + 1 + 0.6 + (money - 60)*0.015;
			System.out.println(jiangjin + "万元");
		} else if (money > 100) {
			double jiangjin = add(3.95, mul(0.01, sub(money, 100)));// 1+ 0.75 + 1 + 0.6 + 0.6 + (money - 100)*0.01;
			System.out.println(jiangjin + "万元");
		}

	}

	// 相加
	public static double add(double d1, double d2) {
		BigDecimal b1 = new BigDecimal(Double.toString(d1));
		BigDecimal b2 = new BigDecimal(Double.toString(d2));
		return b1.add(b2).doubleValue();

	}

	// 相减
	public static double sub(double d1, double d2) {
		BigDecimal b1 = new BigDecimal(Double.toString(d1));
		BigDecimal b2 = new BigDecimal(Double.toString(d2));
		return b1.subtract(b2).doubleValue();

	}

	// 相乘
	public static double mul(double d1, double d2) {
		BigDecimal b1 = new BigDecimal(Double.toString(d1));
		BigDecimal b2 = new BigDecimal(Double.toString(d2));
		return b1.multiply(b2).doubleValue();

	}

	@Test
	public void test7() {
		for (int i = 100; i <= 200; i++) {
			int j = 2;
			for (; j < i; j++) {
				if (i % j == 0) {
					break;
				}
			}
			if (i == j) {

				System.out.println(i);
			}
		}
	}

}
